Skip to content

Conversation

@ZhangYiXiSucceed
Copy link

拉取/合并请求描述:(PR description)

[

为什么提交这份PR (why to submit this PR)

add wdt support for gd32vw553h
image

image

你的解决方案是什么 (what is your solution)

请提供验证的bsp和config (provide the config and bsp)

  • BSP:
  • .config:
  • action:

]

当前拉取/合并请求的状态 Intent for your PR

必须选择一项 Choose one (Mandatory):

  • 本拉取/合并请求是一个草稿版本 This PR is for a code-review and is intended to get feedback
  • 本拉取/合并请求是一个成熟版本 This PR is mature, and ready to be integrated into the repo

代码质量 Code Quality:

我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:

  • 已经仔细查看过代码改动的对比 Already check the difference between PR and old code
  • 代码风格正确,包括缩进空格,命名及其他风格 Style guide is adhered to, including spacing, naming and other styles
  • 没有垃圾代码,代码尽量精简,不包含#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up
  • 所有变更均有原因及合理的,并且不会影响到其他软件组件代码或BSP All modifications are justified and not affect other components or BSP
  • 对难懂代码均提供对应的注释 I've commented appropriately where code is tricky
  • 代码是高质量的 Code in this PR is of high quality
  • 已经使用formatting 等源码格式化工具确保格式符合RT-Thread代码规范 This PR complies with RT-Thread code specification
  • 如果是新增bsp, 已经添加ci检查到.github/ALL_BSP_COMPILE.json 详细请参考链接BSP自查

@github-actions
Copy link

github-actions bot commented Feb 6, 2026

👋 感谢您对 RT-Thread 的贡献!Thank you for your contribution to RT-Thread!

为确保代码符合 RT-Thread 的编码规范,请在你的仓库中执行以下步骤运行代码格式化工作流(如果格式化CI运行失败)。
To ensure your code complies with RT-Thread's coding style, please run the code formatting workflow by following the steps below (If the formatting of CI fails to run).


🛠 操作步骤 | Steps

  1. 前往 Actions 页面 | Go to the Actions page
    点击进入工作流 → | Click to open workflow →

  2. 点击 Run workflow | Click Run workflow

  • 设置需排除的文件/目录(目录请以"/"结尾)
    Set files/directories to exclude (directories should end with "/")
  • 将目标分支设置为 \ Set the target branch to:feature/gd32vw553h-eval-add-wdt-support
  • 设置PR number为 \ Set the PR number to:11181
  1. 等待工作流完成 | Wait for the workflow to complete
    格式化后的代码将自动推送至你的分支。
    The formatted code will be automatically pushed to your branch.

完成后,提交将自动更新至 feature/gd32vw553h-eval-add-wdt-support 分支,关联的 Pull Request 也会同步更新。
Once completed, commits will be pushed to the feature/gd32vw553h-eval-add-wdt-support branch automatically, and the related Pull Request will be updated.

如有问题欢迎联系我们,再次感谢您的贡献!💐
If you have any questions, feel free to reach out. Thanks again for your contribution!

@Rbb666
Copy link
Member

Rbb666 commented Feb 10, 2026

请为wdt驱动添加ci-attach

参考:https://club.rt-thread.org/ask/article/5edd0f0940a57129.html

select RT_SERIAL_USING_DMA
default n

config BSP_USING_UART3
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这部分串口和此pr不太相关,有必要提交上来吗?

#include <board.h>
#include <rtthread.h>


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

请删除多余的换行

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to add Watchdog Timer (WDT) support for the GD32VW553H-EVAL BSP by introducing a new WDT driver, wiring it into the GD32 RISC-V driver build, and exposing WDT-related Kconfig options for the board.

Changes:

  • Add a new GD32 RISC-V watchdog driver (drv_wdt.c) implementing RT-Thread watchdog device ops.
  • Update SConscript to compile the WDT driver when RT_USING_WDT + SOC_GD32VW553H are enabled.
  • Extend board Kconfig to expose WDT options (and also UART3/UART4 options).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 11 comments.

File Description
bsp/gd32/risc-v/libraries/gd32_drivers/drv_wdt.c New watchdog driver implementation plus shell test commands
bsp/gd32/risc-v/libraries/gd32_drivers/SConscript Adds conditional compilation of drv_wdt.c for GD32VW553H
bsp/gd32/risc-v/gd32vw553h-eval/board/Kconfig Adds board-level WDT configs (and UART3/4 related configs)

Comment on lines +141 to +143
rt_device_control(hw_dev, RT_DEVICE_CTRL_WDT_START, RT_NULL);
rt_device_control(hw_dev, RT_DEVICE_CTRL_WDT_KEEPALIVE, RT_NULL);
}
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[bug/类别: bug]: Test sample functions return type mismatch / 测试示例函数返回类型与返回值不匹配

English: fwdt_test_sample() / wwdt_test_sample() are declared to return int but exit without returning a value. This can trigger compiler warnings or errors (often treated as -Werror in CI). Please return a proper status code on success paths.
中文:fwdt_test_sample() / wwdt_test_sample() 声明为返回 int,但函数末尾没有返回值。这会触发编译警告甚至错误(CI 常用 -Werror)。建议在成功路径返回明确的状态码。

Copilot uses AI. Check for mistakes.
Comment on lines +60 to +78
config BSP_USING_UART3
bool "Enable UART3"
default n

config BSP_UART3_RX_USING_DMA
bool "Enable UART3 RX DMA"
depends on BSP_USING_UART3
select RT_SERIAL_USING_DMA
default n

config BSP_USING_UART4
bool "Enable UART4"
default n

config BSP_UART4_RX_USING_DMA
bool "Enable UART4 RX DMA"
depends on BSP_USING_UART4
select RT_SERIAL_USING_DMA
default n
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[discrepancy_with_pr_description/类别: discrepancy_with_pr_description]: PR includes UART3/4 Kconfig changes not mentioned / PR 包含未在描述中说明的 UART3/4 配置变更

English: This PR is titled/justified as adding WDT support, but this Kconfig hunk also introduces UART3/UART4 (and DMA) options. If these UART options are required for WDT support, please explain the dependency in the PR description; otherwise, consider moving UART-related changes into a separate PR to keep the change set focused.
中文:本 PR 标题/说明是新增 WDT 支持,但该 Kconfig 片段同时新增了 UART3/UART4(及 DMA)选项。如果这些 UART 选项与 WDT 支持存在依赖关系,请在 PR 描述中说明原因;否则建议将 UART 相关修改拆分到单独 PR,保持改动聚焦。

Copilot uses AI. Check for mistakes.
Comment on lines +33 to 34
if GetDepend(['RT_USING_WDT', 'SOC_GD32VW553H']):
src += ['drv_wdt.c']
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[discrepancy_with_pr_description/类别: discrepancy_with_pr_description]: PR description template not filled (verification/config/action) / PR 描述模板未填写(验证信息/配置/action)

English: The PR description still contains the unfilled template sections and does not provide the verified BSP path, relevant .config changes, or CI/action link. RT-Thread’s PR template requires these details for review and reproducibility; please complete them before merge.
中文:PR 描述仍保留未替换的模板内容,且未提供已验证的 BSP 路径、关键 .config 变更以及 CI/action 链接。RT-Thread 的 PR 模板要求这些信息用于审查与复现,建议在合入前补充完整。

Copilot uses AI. Check for mistakes.
Comment on lines +19 to +22
#if defined(BSP_USING_FWDT)
#define HW_WDGT_DEV_NAME "fwdgt"
#elif defined(BSP_USING_WWDT)
#define HW_WDGT_DEV_NAME "wwdgt"
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[bug/类别: bug]: HW_WDGT_DEV_NAME can be undefined / HW_WDGT_DEV_NAME 可能未定义导致编译失败

English: HW_WDGT_DEV_NAME is only defined when BSP_USING_FWDT or BSP_USING_WWDT is set. It is later used unconditionally, so enabling WDT without selecting a concrete type will break the build. Please add a compile-time check (#error) here or enforce a choice in Kconfig to guarantee exactly one implementation.
中文:HW_WDGT_DEV_NAME 只在定义了 BSP_USING_FWDTBSP_USING_WWDT 时才会生成;后续代码会无条件使用它,因此开启 WDT 但未选择具体类型会导致编译失败。建议在此处增加编译期检查(#error),或在 Kconfig 中用 choice 保证只能且必须选择一种实现。

Suggested change
#if defined(BSP_USING_FWDT)
#define HW_WDGT_DEV_NAME "fwdgt"
#elif defined(BSP_USING_WWDT)
#define HW_WDGT_DEV_NAME "wwdgt"
#if defined(BSP_USING_FWDT) && defined(BSP_USING_WWDT)
#error "Only one of BSP_USING_FWDT or BSP_USING_WWDT can be defined when RT_USING_WDT is enabled."
#endif
#if defined(BSP_USING_FWDT)
#define HW_WDGT_DEV_NAME "fwdgt"
#elif defined(BSP_USING_WWDT)
#define HW_WDGT_DEV_NAME "wwdgt"
#else
#error "Please enable BSP_USING_FWDT or BSP_USING_WWDT when RT_USING_WDT is enabled."

Copilot uses AI. Check for mistakes.
Comment on lines +73 to +75
time_msec = *(rt_uint32_t*)arg;
wdgt_count = (rt_uint32_t)((float)((float)1/0.78)*time_msec) + 0x3F;
wwdgt_config(wdgt_count, window_value, WWDGT_CFG_PSC_DIV8);
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[performance/类别: performance]: Floating-point math in timeout calculation / 超时计算使用浮点运算

English: The WWDT timeout calculation uses floating-point operations ((float)1/0.78) inside the driver. On many embedded targets this pulls in soft-float routines and increases code size and CPU cost. Please replace with an integer/rational approximation and add bounds checking to keep wdgt_count within the hardware-allowed range.
中文:WWDT 超时计算在驱动里使用了浮点运算((float)1/0.78)。在很多嵌入式平台上会引入软浮点库,增加代码体积和 CPU 开销。建议改为整数/分数近似计算,并增加边界检查,确保 wdgt_count 在硬件允许范围内。

Copilot uses AI. Check for mistakes.
Comment on lines +124 to +125
LOG_D("hwtimer sample run failed! can't find %s device!", HW_WDGT_DEV_NAME);
return -RT_ERROR;
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[error_message/类别: error_message]: Copy-pasted error message refers to hwtimer / 复制粘贴导致错误信息指向 hwtimer

English: The error message says "hwtimer sample run failed" inside the watchdog sample. This is misleading when debugging. Please update the message to refer to WDT/WWDT/FWDT consistently.
中文:看门狗示例中的错误日志写成了 "hwtimer sample run failed",会误导排查问题。建议将日志内容统一改为与 WDT/WWDT/FWDT 相关的描述。

Copilot uses AI. Check for mistakes.
Comment on lines +108 to +113
config BSP_USING_FWDT
bool "Enable FWDT"
default y
config BSP_USING_WWDT
bool "Enable WWDT"
default n
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[api_design/类别: api_design]: WDT type selection allows invalid combinations / WDT 类型选择可能产生无效组合

English: BSP_USING_FWDT and BSP_USING_WWDT are independent bools under BSP_USING_WDT, so users can select both or neither. The driver assumes exactly one is defined (it needs HW_WDGT_DEV_NAME and selects different implementations). Please model this as a choice (FWDT vs WWDT) or add mutual depends on constraints and ensure at least one option is selected.
中文:在 BSP_USING_WDT 下,BSP_USING_FWDTBSP_USING_WWDT 是两个独立的 bool,用户可能同时选中或都不选。驱动实现假设只会定义其中一个(需要 HW_WDGT_DEV_NAME 并选择不同实现)。建议改为 choice(FWDT/WWDT 二选一),或增加互斥 depends on 约束并保证至少选择一个。

Suggested change
config BSP_USING_FWDT
bool "Enable FWDT"
default y
config BSP_USING_WWDT
bool "Enable WWDT"
default n
choice
prompt "Select WDT type"
default BSP_USING_FWDT
config BSP_USING_FWDT
bool "Enable FWDT"
config BSP_USING_WWDT
bool "Enable WWDT"
endchoice

Copilot uses AI. Check for mistakes.
Comment on lines +13 to +16




Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[bug/类别: bug]: Missing required device header include / 缺少必要的设备头文件包含

English: This file uses rt_watchdog_t, rt_watchdog_ops, and RT_DEVICE_CTRL_WDT_* APIs, but it only includes <rtthread.h>. In this codebase those watchdog types/macros are provided via <rtdevice.h> (and drivers/dev_watchdog.h), so this will fail to compile when WDT is enabled.
中文:该文件使用了 rt_watchdog_trt_watchdog_ops 以及 RT_DEVICE_CTRL_WDT_* 等接口,但只包含了 <rtthread.h>。在本仓库中这些定义来自 <rtdevice.h>(以及 drivers/dev_watchdog.h),因此开启 WDT 后会编译失败。

Suggested change
#include <rtdevice.h>

Copilot uses AI. Check for mistakes.
Comment on lines +67 to +68
ErrStatus res = fwdgt_prescaler_value_config(FWDGT_PSC_DIV32);
res = fwdgt_reload_value_config(wdgt_count);
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[bug/类别: bug]: Undefined/incorrect FWDT configuration API usage / FWDT 配置 API 使用错误或未定义

English: The FWDT timeout path calls fwdgt_prescaler_value_config() and fwdgt_reload_value_config(), but these symbols are not present anywhere else in this repository (search only finds them here). This will cause a link/compile failure. Please switch to the actual FWDT configuration API used by the vendor library (e.g., fwdgt_write_enable() + fwdgt_config(reload, prescaler)), and handle its return value.
中文:FWDT 超时设置分支调用了 fwdgt_prescaler_value_config()fwdgt_reload_value_config(),但这两个符号在仓库其他地方不存在(搜索仅在此处命中),会导致编译/链接失败。建议改用芯片库真实提供的配置接口(如 fwdgt_write_enable() + fwdgt_config(reload, prescaler)),并检查返回值。

Suggested change
ErrStatus res = fwdgt_prescaler_value_config(FWDGT_PSC_DIV32);
res = fwdgt_reload_value_config(wdgt_count);
/* configure FWDT: enable write access, then set reload and prescaler */
ErrStatus res = fwdgt_write_enable();
if (res == SUCCESS)
{
res = fwdgt_config(wdgt_count, FWDGT_PSC_DIV32);
}
if (res != SUCCESS)
{
LOG_E("failed to config FWDT, timeout=%d sec,count=%d res=%d", time_sec, wdgt_count, res);
return -RT_ERROR;
}

Copilot uses AI. Check for mistakes.
Comment on lines +64 to +76
/* set timeout sec*/
time_sec = *(rt_uint32_t*)arg;
wdgt_count = 32*1000/32*time_sec;
ErrStatus res = fwdgt_prescaler_value_config(FWDGT_PSC_DIV32);
res = fwdgt_reload_value_config(wdgt_count);
LOG_D("timeout=%d sec,count=%d res=%d ", time_sec, wdgt_count, res);
#elif defined(BSP_USING_WWDT)
/* set timeout ms */
window_value = 0x7F;
time_msec = *(rt_uint32_t*)arg;
wdgt_count = (rt_uint32_t)((float)((float)1/0.78)*time_msec) + 0x3F;
wwdgt_config(wdgt_count, window_value, WWDGT_CFG_PSC_DIV8);
LOG_D("timeout=%d msec,count=%d ", time_msec, wdgt_count);
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[api_design/类别: api_design]: RT watchdog timeout unit mismatch (seconds vs ms) / 看门狗超时单位与 RT 接口不一致(秒 vs 毫秒)

English: RT_DEVICE_CTRL_WDT_SET_TIMEOUT is defined as “timeout in seconds” (see components/drivers/include/drivers/dev_watchdog.h), but the WWDT branch treats the argument as milliseconds (time_msec) and the sample passes 40. This breaks the standard watchdog device contract and will confuse users/applications. Please keep the control argument in seconds (and convert internally if needed) or expose a separate, clearly documented control command.
中文:RT_DEVICE_CTRL_WDT_SET_TIMEOUTcomponents/drivers/include/drivers/dev_watchdog.h 中定义为“单位:秒”,但 WWDT 分支把参数当成毫秒(time_msec)处理,示例也传入 40。这会破坏标准 watchdog 设备接口契约并误导应用。建议保持控制参数单位为秒(内部再换算),或提供单独且清晰文档化的控制命令。

Suggested change
/* set timeout sec*/
time_sec = *(rt_uint32_t*)arg;
wdgt_count = 32*1000/32*time_sec;
ErrStatus res = fwdgt_prescaler_value_config(FWDGT_PSC_DIV32);
res = fwdgt_reload_value_config(wdgt_count);
LOG_D("timeout=%d sec,count=%d res=%d ", time_sec, wdgt_count, res);
#elif defined(BSP_USING_WWDT)
/* set timeout ms */
window_value = 0x7F;
time_msec = *(rt_uint32_t*)arg;
wdgt_count = (rt_uint32_t)((float)((float)1/0.78)*time_msec) + 0x3F;
wwdgt_config(wdgt_count, window_value, WWDGT_CFG_PSC_DIV8);
LOG_D("timeout=%d msec,count=%d ", time_msec, wdgt_count);
/* set timeout sec */
time_sec = *(rt_uint32_t*)arg;
wdgt_count = 32*1000/32*time_sec;
ErrStatus res = fwdgt_prescaler_value_config(FWDGT_PSC_DIV32);
res = fwdgt_reload_value_config(wdgt_count);
LOG_D("timeout=%d sec,count=%d res=%d ", time_sec, wdgt_count, res);
#elif defined(BSP_USING_WWDT)
/* set timeout sec (convert to ms internally) */
window_value = 0x7F;
time_sec = *(rt_uint32_t*)arg;
time_msec = time_sec * 1000U;
wdgt_count = (rt_uint32_t)((float)((float)1/0.78)*time_msec) + 0x3F;
wwdgt_config(wdgt_count, window_value, WWDGT_CFG_PSC_DIV8);
LOG_D("timeout=%d sec (%d msec), count=%d ", time_sec, time_msec, wdgt_count);

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

BSP: GD32 BSP related with GD32 BSP

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants